package cloudbus

import "zstackgo/pkg/header/message"

var (
	_ CloudBusCallBack = new(CloudBusCallBackImpl[any])
)

type CloudBusCallBack interface {
	Run(reply *message.MessageReply)
}

type CloudBusCallBackImpl[T any] struct {
	backups []T
	fn      func(*message.MessageReply)
}

func NewCloudBusCallBackImpl[T any](fn func(*message.MessageReply), one T, others ...T) *CloudBusCallBackImpl[T] {
	i := &CloudBusCallBackImpl[T]{
		fn: fn,
	}

	i.backups = append(i.backups, one)
	if len(others) > 0 {
		i.backups = append(i.backups, others...)
	}

	return i
}

func (impl *CloudBusCallBackImpl[T]) Run(reply *message.MessageReply) {
	impl.fn(reply)
}
